//Filename: exti.c

#include "includes.h"
int num=0;
void EXTIKeyInit(void)
{
	EXTI_InitTypeDef Exit_InitStructure;
	
	KeyInit();
	
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource0);
	GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource1);
	Exit_InitStructure.EXTI_Line=EXTI_Line0 | EXTI_Line1;
	Exit_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
	Exit_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
	Exit_InitStructure.EXTI_LineCmd = ENABLE;
	EXTI_Init(&Exit_InitStructure);
	
	NVIC_EnableIRQ(EXTI0_IRQn);	
	NVIC_EnableIRQ(EXTI1_IRQn);	
	NVIC_SetPriority(EXTI0_IRQn, 5);
	NVIC_SetPriority(EXTI1_IRQn, 6);
}

void EXTI0_IRQHandler()
{
	LED(1, LED_ON);
	num++;
	EXTI_ClearFlag(EXTI_Line0);
	NVIC_ClearPendingIRQ(EXTI0_IRQn);
}

void EXTI1_IRQHandler()
{
	LED(2,LED_ON);
	num--;
	EXTI_ClearFlag(EXTI_Line1);
	NVIC_ClearPendingIRQ(EXTI1_IRQn);
}
